**************************************************************************
*																		*
*			Campaign Panel Book Chapter 5 - Communication Variables								*
*																		*
*************************************************************************

use "${data}\ZA5704_en_v3-2-0.dta", clear


**************************************************************************
*			Reception of the TV-Debate yes/no									*
*																		*
**************************************************************************

fre kp?_1800*
// Only respondents who did not participate in W5 received this question at a 
// later time

* Nobody could have seen the debate before wave 5
foreach welle of numlist 1/4 {
gen watcheddebate`welle' = 0 
}

gen watcheddebate5 = 0 if kp5_1800==3
replace watcheddebate5 = 1 if kp5_1800==1 | kp5_1800==2

tab watcheddebate5 kp5_1800

* Insert the same value after the event
gen watcheddebate6 = watcheddebate5
gen watcheddebate7 = watcheddebate6


***************************************************************************
**** Wahlomat used/not used										***********
***************************************************************************

// The party-specific variables are placed at the top
// Here only general usage
// General accord/discord with a party would also be interesting but was not asked
// for in the survey

tab1 kp5_3490 kp6_3490 kp7_3490, nolabel
tab kp6_3490 kp5_3490
tab1 kp5_3510 kp6_3510 kp7_3510

foreach welle of numlist 1/7 {
    gen wahlomatg`welle' = 0
   }


foreach welle of numlist 5/7 {
    replace wahlomatg`welle' = 1 if kp5_3490==1 
}  

foreach welle of numlist 6/7 {
    replace wahlomatg`welle' = 1 if kp6_3490==1 
}  

foreach welle in 7 {
    replace wahlomatg`welle' = 1 if kp7_3490==1 
}  




**************************************************************************
***			Reception of election arena yes/no							****
*************************************************************************

tab1 kp?_2980?
tab1 kp?_2980?, nolabel
mvdecode kp?_2980?, mv(-99/-1)

foreach welle of numlist 1/5 {
      gen wahlarenag_mg`welle' = 0
	  gen wahlarenag_sg`welle' = 0
     }
	 
foreach welle of numlist 6 {
    recode kp`welle'_2980a (1 2=1) (3=0) (else=.), gen(wahlarenag_mg`welle')
	recode kp`welle'_2980b (1 2=1) (3=0) (else=.), gen(wahlarenag_sg`welle')
     }
	 	 
gen wahlarenag_mg7=wahlarenag_mg6
gen wahlarenag_sg7=wahlarenag_sg6


********************************************************************************
**
** Talks about politics
**
********************************************************************************
// The party-specific variables are placed further at the top, these could be
// relevant for consonant and dissonant information.
// For turnout the frequency of talks should be more important.
// Here the average values for each wave are calculated.

tab1 kp2_1932a-kp2_1932f
tab1 kp2_1932a-kp2_1932f, nolabel

mvdecode kp?_1932?, mv(-99/-1)
mvdecode kp?_1931?, mv(-99/-1)

foreach welle of numlist 1 {
	gen gesprh1`welle' = (kp`welle'_1931a-1)/7
	gen gesprh2`welle' = (kp`welle'_1931b-1)/7
	gen gesprh3`welle' = (kp`welle'_1931c-1)/7
	gen gesprh4`welle' = (kp`welle'_1931d-1)/7
	gen gesprh5`welle' = (kp`welle'_1931e-1)/7
	egen gesprhi`welle' = rowmean(gesprh?`welle')
}




foreach welle of numlist 2/7 {
   gen gesprh1`welle' = (kp`welle'_1932a-1)/7
   gen gesprh2`welle' = (kp`welle'_1932b-1)/7
   gen gesprh3`welle' = (kp`welle'_1932c-1)/7
   gen gesprh4`welle' = (kp`welle'_1932d-1)/7
   gen gesprh5`welle' = (kp`welle'_1932e-1)/7
   egen gesprhi`welle' = rowmean(gesprh?`welle')
}

tab1 gesprhi*

* Index

forvalues num=1/7 {	
egen gesprhin`num' = rowtotal(gesprh1`num'-gesprh5`num'), missing
replace gesprhin`num' = 1 if gesprhin`num'>1 & gesprhin`num'~=.
lab var gesprhin`num' "Political talk"
}


tab1 gesprhin*
tab gesprhin3 gesprhi3


********************************************************************************
**
** Calculation of indexes for party contacts
**
********************************************************************************

** Indexes

mvdecode kp?_421??, mv(-99 -95 -93)

foreach welle of numlist 2/7 {			
egen pk_kundgebi`welle' = anycount(kp`welle'_421aa kp`welle'_421ac ///
 kp`welle'_421ad kp`welle'_421ae kp`welle'_421af), values(1)
replace pk_kundgebi`welle' = . if kp`welle'_421aa>1 & kp`welle'_421ac>1 ///
 & kp`welle'_421ad>1 & kp`welle'_421ae>1 & kp`welle'_421af>1
gen pk_kundgebin`welle'=pk_kundgebi`welle'/5
egen pk_flumaili`welle' = anycount(kp`welle'_421ba kp`welle'_421bc ///
 kp`welle'_421bd kp`welle'_421be kp`welle'_421bf), values(1)
replace pk_flumaili`welle' = . if kp`welle'_421ba>1 & kp`welle'_421bc>1 ///
 & kp`welle'_421bd>1 & kp`welle'_421be>1 & kp`welle'_421bf>1
gen pk_flumailin`welle'=pk_flumaili`welle'/5
egen pk_tvspoti`welle' = anycount(kp`welle'_421da kp`welle'_421dc ///
 kp`welle'_421dd kp`welle'_421de kp`welle'_421df), values(1)
replace pk_tvspoti`welle' = . if kp`welle'_421da>1 & kp`welle'_421dc>1 ///
 & kp`welle'_421dd>1 & kp`welle'_421de>1 & kp`welle'_421df>1
gen pk_tvspotin`welle'=pk_tvspoti`welle'/5
egen pk_radioi`welle' = anycount(kp`welle'_421ea kp`welle'_421ec ///
 kp`welle'_421ed kp`welle'_421ee kp`welle'_421ef), values(1)
replace pk_radioi`welle' = . if kp`welle'_421ea>1 & kp`welle'_421ec>1 ///
 & kp`welle'_421ed>1 & kp`welle'_421ee>1 & kp`welle'_421ef>1
gen pk_radioin`welle'=pk_radioi`welle'/5
egen pk_plakati`welle' = anycount(kp`welle'_421ga kp`welle'_421gc ///
 kp`welle'_421gd kp`welle'_421ge kp`welle'_421gf), values(1)
replace pk_plakati`welle' = . if kp`welle'_421ga>1 & kp`welle'_421gc>1 ///
 & kp`welle'_421gd>1 & kp`welle'_421ge>1 & kp`welle'_421gf>1
gen pk_plakatin`welle'=pk_plakati`welle'/5
egen pk_standi`welle' = anycount(kp`welle'_421ha kp`welle'_421hc ///
 kp`welle'_421hd kp`welle'_421he kp`welle'_421hf), values(1)
replace pk_standi`welle' = . if kp`welle'_421ha>1 & kp`welle'_421hc>1 ///
 & kp`welle'_421hd>1 & kp`welle'_421he>1 & kp`welle'_421hf>1
gen pk_standin`welle'=pk_standi`welle'/5
egen pk_websitei`welle' = anycount(kp`welle'_421ka kp`welle'_421kc ///
 kp`welle'_421kd kp`welle'_421ke kp`welle'_421kf), values(1)
replace pk_websitei`welle' = . if kp`welle'_421ka>1 & kp`welle'_421kc>1 ///
 & kp`welle'_421kd>1 & kp`welle'_421ke>1 & kp`welle'_421kf>1
gen pk_websitein`welle'=pk_websitei`welle'/5
egen pk_gesamti`welle' = rowtotal(pk_kundgebi`welle' pk_flumaili`welle' ///
	pk_tvspoti`welle' pk_radioi`welle' pk_plakati`welle' pk_standi`welle' ///
	pk_websitei`welle'), missing
gen pk_gesamtino`welle'=pk_gesamti`welle'/35
}

fre pk_gesamtino2

gen pk_gesamtino1 = pk_gesamtino2

fre kp2_421da



********************************************************************************
**
** Consumption of print media
**
********************************************************************************

// Starting here this cannot me used exactly the same way for turnout.

// Bild


foreach welle of numlist 1 {
   recode kp`welle'_1721a (-99/-1=.), gen(pr_bild`welle')
   replace pr_bild`welle' = (pr_bild`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1661a (-99/-1=.), gen(pr_bild`welle')
   replace pr_bild`welle' = (pr_bild`welle'-1)/7
}

tab pr_bild4

// Frankfurter Rundschau


foreach welle of numlist 1 {
   recode kp`welle'_1721b (-99/-1=.), gen(pr_fr`welle')
   replace pr_fr`welle' = (pr_fr`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1661b (-99/-1=.), gen(pr_fr`welle')
   replace pr_fr`welle' = (pr_fr`welle'-1)/7
}

// FAZ


foreach welle of numlist 1 {
   recode kp`welle'_1721c (-99/-1=.), gen(pr_faz`welle')
   replace pr_faz`welle' = (pr_faz`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1661c (-99/-1=.), gen(pr_faz`welle')
   replace pr_faz`welle' = (pr_faz`welle'-1)/7
}


// SZ


foreach welle of numlist 1 {
   recode kp`welle'_1721d (-99/-1=.), gen(pr_sz`welle')
   replace pr_sz`welle' = (pr_sz`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1661d (-99/-1=.), gen(pr_sz`welle')
   replace pr_sz`welle' = (pr_sz`welle'-1)/7
}


// taz


foreach welle of numlist 1 {
   recode kp`welle'_1721e (-99/-1=.), gen(pr_taz`welle')
   replace pr_taz`welle' = (pr_taz`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1661e (-99/-1=.), gen(pr_taz`welle')
   replace pr_taz`welle' = (pr_taz`welle'-1)/7
}


// Welt


foreach welle of numlist 1 {
   recode kp`welle'_1721f (-99/-1=.), gen(pr_welt`welle')
   replace pr_welt`welle' = (pr_welt`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1661f (-99/-1=.), gen(pr_welt`welle')
   replace pr_welt`welle' = (pr_welt`welle'-1)/7
}



********************************************************************************
**
** Consumption of TV News
**
********************************************************************************


// ARD

foreach welle of numlist 1 {
   recode kp`welle'_1741a (-99/-1=.), gen(tv_ard`welle')
   replace tv_ard`welle' = (tv_ard`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1681a (-99/-1=.), gen(tv_ard`welle')
   replace tv_ard`welle' = (tv_ard`welle'-1)/7
}


// ZDF

foreach welle of numlist 1 {
   recode kp`welle'_1741b (-99/-1=.), gen(tv_zdf`welle')
   replace tv_zdf`welle' = (tv_zdf`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1681b (-99/-1=.), gen(tv_zdf`welle')
   replace tv_zdf`welle' = (tv_zdf`welle'-1)/7
}


// RTL

foreach welle of numlist 1 {
   recode kp`welle'_1741c (-99/-1=.), gen(tv_rtl`welle')
   replace tv_rtl`welle' = (tv_rtl`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1681c (-99/-1=.), gen(tv_rtl`welle')
   replace tv_rtl`welle' = (tv_rtl`welle'-1)/7
}


// SAT 1

foreach welle of numlist 1 {
   recode kp`welle'_1741d (-99/-1=.), gen(tv_sat`welle')
   replace tv_sat`welle' = (tv_sat`welle'-1)/7
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1681d (-99/-1=.), gen(tv_sat`welle')
   replace tv_sat`welle' = (tv_sat`welle'-1)/7
}

tab tv_sat4

********************************************************************************
**
** Newsmagazines - online
**
********************************************************************************

// Spiegel-Online

foreach welle of numlist 1 {
   recode kp`welle'_1760aa (-99/-1=.), gen(im_spon`welle')
   replace im_spon`welle' = (im_spon`welle'-2)*-1
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1700aa (-99/-1=.), gen(im_spon`welle')
   replace im_spon`welle' = (im_spon`welle'-2)*-1
}

tab im_spon4

// Focus-Online

foreach welle of numlist 1 {
   recode kp`welle'_1760ba (-99/-1=.), gen(im_fcon`welle')
   replace im_fcon`welle' = (im_fcon`welle'-2)*-1
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1700ba (-99/-1=.), gen(im_fcon`welle')
   replace im_fcon`welle' = (im_fcon`welle'-2)*-1
}



// Zeit-Online

foreach welle of numlist 1 {
   recode kp`welle'_1760ca (-99/-1=.), gen(im_zon`welle')
   replace im_zon`welle' = (im_zon`welle'-2)*-1
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1700ca (-99/-1=.), gen(im_zon`welle')
   replace im_zon`welle' = (im_zon`welle'-2)*-1
}


// Stern-Online

foreach welle of numlist 1 {
   recode kp`welle'_1760da (-99/-1=.), gen(im_ston`welle')
   replace im_ston`welle' = (im_ston`welle'-2)*-1
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1700da (-99/-1=.), gen(im_ston`welle')
   replace im_ston`welle' = (im_ston`welle'-2)*-1
}



********************************************************************************
**
** Newsmagazines - Print
**
********************************************************************************


// Spiegel

foreach welle of numlist 1 {
   recode kp`welle'_1760ab (-99/-1=.), gen(m_spgl`welle')
   replace m_spgl`welle' = (m_spgl`welle'-2)*-1
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1700ab (-99/-1=.), gen(m_spgl`welle')
   replace m_spgl`welle' = (m_spgl`welle'-2)*-1
}



// Focus

foreach welle of numlist 1 {
   recode kp`welle'_1760bb (-99/-1=.), gen(m_fcus`welle')
   replace m_fcus`welle' = (m_fcus`welle'-2)*-1
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1700bb (-99/-1=.), gen(m_fcus`welle')
   replace m_fcus`welle' = (m_fcus`welle'-2)*-1
}



// Zeit

foreach welle of numlist 1 {
   recode kp`welle'_1760cb (-99/-1=.), gen(m_zeit`welle')
   replace m_zeit`welle' = (m_zeit`welle'-2)*-1
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1700cb (-99/-1=.), gen(m_zeit`welle')
   replace m_zeit`welle' = (m_zeit`welle'-2)*-1
}


// Stern

foreach welle of numlist 1 {
   recode kp`welle'_1760db (-99/-1=.), gen(m_strn`welle')
   replace m_strn`welle' = (m_strn`welle'-2)*-1
}


foreach welle of numlist 2/7 {
   recode kp`welle'_1700db (-99/-1=.), gen(m_strn`welle')
   replace m_strn`welle' = (m_strn`welle'-2)*-1
}



*----------------------------------------------------------
* Use value from wave 2 in wave 1 for all media
*---------------------------------------------------------------

foreach stub in pr_bild pr_fr pr_faz pr_taz pr_welt pr_sz tv_ard tv_zdf ///
   tv_rtl tv_sat im_spon im_fcon im_ston im_zon m_spgl m_fcus m_zeit m_strn {
      replace `stub'1 = `stub'2
}

********************************************************************************
**
** Political internet usage
**
********************************************************************************

tab kp2_1600
tab kp2_1600, nol

foreach welle of numlist 2/7 {
   recode kp`welle'_1600 (-99/-93=.), gen(i_nupol`welle')
   replace i_nupol`welle' = (i_nupol`welle'-1)/7
}

gen i_nupol1=i_nupol2  //Replacement for wave 1
tab1 i_nupol?


********************************************************************************
**
** Indexes Media Consumption
**
********************************************************************************



/*
1. National papers, 
2. Bildzeitung,
3. other daily newspapers (mainly regional papers)
*/

forvalues num=1/7 {	
egen pr_paper`num' = rowtotal(pr_sz`num' pr_faz`num' pr_fr`num' ///
	pr_taz`num' pr_welt`num'), missing
replace pr_paper`num' = 1 if pr_paper`num'>1 & pr_paper`num'~=.
lab var pr_paper`num' "Daily paper"
}

fre pr_paper?

fre pr_bild1		//Bildzeitung already coded

tab1 kp1_1721g kp2_1661g
tab1 kp1_1721g kp2_1661g, nol
gen pr_andz1=(kp1_1721g-1)/7 ///
	if kp1_1721g<=8
replace pr_andz1 = 0 if kp1_1721g==-100
replace pr_andz1 = . if kp1_1721g==-99

tab kp1_1721g pr_andz1, m

tab kp6_1661g
tab kp6_1661g, nol

foreach wave of numlist 2/7 {
gen pr_andz`wave' = (kp`wave'_1661g-1)/7 ///
	if kp`wave'_1661g<=8
replace pr_andz`wave' = 0 if kp`wave'_1661g==-100 | kp`wave'_1661g==-95 | kp`wave'_1661g==-93
replace pr_andz`wave' = . if kp`wave'_1661g==-99 | kp`wave'_1661g==-92
} 

tab kp2_1661g pr_andz2, m

mean pr_paper2 pr_bild2 pr_andz2  

tabstat pr_andz? , sta (n min max mean sd)


* TV-News 

foreach num of numlist 1/7 {
egen tv_oeff`num' = rowtotal(tv_ard`num' tv_zdf`num'), missing
replace tv_oeff`num' = 1 if tv_oeff`num'>1 & tv_oeff`num'!=.
lab var tv_oeff`num' "TV news (public)" 
}


forvalues num=1/7 {	
egen tv_privat`num' = rowtotal(tv_rtl`num' tv_sat`num'), missing
replace tv_privat`num' = 1 if tv_privat`num'>1 & tv_privat`num'!=.
lab var tv_privat`num' "TV news (private)" 
}

fre tv_oeff? tv_privat?

* Newsmagazines (Print)
/* Attention: Newsmagazines are only released once a week.
The index therefore shows how many different magazines were read in a given 
week. Max = 4*/

forvalues welle=1/7 {
egen m_gesamt`welle' = rowtotal(m_spgl`welle' m_fcus`welle' m_zeit`welle' ///
	m_strn`welle'), missing
gen m_gesamti`welle'= m_gesamt`welle'/4
lab var m_gesamti`welle' "Weekly paper" 
}

tab1 m_gesamt? m_gesamti?


sum m_gesamti?



keep lfdn m_gesamti? tv_privat? tv_oeff? pr_andz? pr_paper? pr_bild? ///
	pk_gesamtino? i_nupol? gesprhin? wahlarenag* wahlomatg* watcheddebate*
	
save "${path}\Reproducible Do-Files\Chapter 5\Data\kommunikation13.dta", replace	

